// 
// Creative Software Group� - http://www.creativesoftwaregroup.com 
// Copyright (c) 2010-2013 
// by Creative Software Group Corporation 
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software. 
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE. 
//

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;

namespace CSG.Modules.aNvarCharTest
{

    /// ----------------------------------------------------------------------------- 
    /// <summary> 
    /// The ViewaNvarCharTest class displays the content 
    /// </summary> 
    /// <remarks> 
    /// </remarks> 
    /// <history> 
    /// </history> 
    /// ----------------------------------------------------------------------------- 
    partial class ViewaNvarCharTest : PortalModuleBase, IActionable
    {

        #region "Private Members"

        // private int _RecordPk = Null.NullInteger; 

        private void FillGrid()
        {
            // Add code here to create a controller, an list of info 
            //    objects, and bind the info object list to the grid.

            aNvarCharTestController myController = new aNvarCharTestController();
            List<aNvarCharTestInfo> myObjectList = new List<aNvarCharTestInfo>(myController.GetaNvarCharTests());
            gvCSG.DataSource = myObjectList;
            gvCSG.DataBind();

        }

        #endregion

        #region "Event Handlers"

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// Page_Load runs when the control is loaded 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                // If this is the first visit to the page, bind the role data to the datalist 
                if (Page.IsPostBack == false)
                {

                    // If you need to do anything to delete anything out side of the grid delete feature and want a confirmation, then uncomment the next line of code.
                    // Remember to uncomment the control in the ascx page for the edit view.
                    // cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');"); 

                    // If this is the first time to this page, fill the Grid View
                    FillGrid();
                }
            }
            catch (Exception exc)
            {
                //Module failed to load 
                Exceptions.ProcessModuleLoadException(this, exc);
            }

        }

        protected void gvCSG_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // 
            // If you need to add, edit, or transform the data as it is being,
            //     bound to the row in the grid; add code here.
            // 

        }
        protected void gvCSG_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            // If grid is not empty, the <Footer> will be shown.
            if (e.CommandName.Equals("Insert"))
            {
                aNvarCharTestInfo myInfoObject = new aNvarCharTestInfo();
                myInfoObject.nvarchar10 = Convert.ToString(((TextBox)gvCSG.FooterRow.Cells[1].FindControl("txtInsnvarchar10")).Text);
                myInfoObject.nvarchar25 = Convert.ToString(((TextBox)gvCSG.FooterRow.Cells[1].FindControl("txtInsnvarchar25")).Text);
                myInfoObject.nvarchar50 = Convert.ToString(((TextBox)gvCSG.FooterRow.Cells[1].FindControl("txtInsnvarchar50")).Text);
                myInfoObject.nvarcharMax = Convert.ToString(((TextBox)gvCSG.FooterRow.Cells[1].FindControl("txtInsnvarcharMax")).Text);
                myInfoObject.VarcharMax = Convert.ToString(((TextBox)gvCSG.FooterRow.Cells[1].FindControl("txtInsVarcharMax")).Text);
                aNvarCharTestController myController = new aNvarCharTestController();
                myController.AddaNvarCharTest(myInfoObject);

                FillGrid();
            }
            // If grid is empty, the <EmptyDataTemplate> will be shown.
            if (e.CommandName.Equals("Add"))
            {
                aNvarCharTestInfo myInfoObject = new aNvarCharTestInfo();
                GridViewRow gvr;
                Table tbl = (Table)gvCSG.Controls[0];
                gvr = (GridViewRow)tbl.Controls[0];
                TableCell emptyRowCell = gvr.Cells[0];
                myInfoObject.nvarchar10 = Convert.ToString(((TextBox)emptyRowCell.FindControl("txtAddnvarchar10")).Text);
                myInfoObject.nvarchar25 = Convert.ToString(((TextBox)emptyRowCell.FindControl("txtAddnvarchar25")).Text);
                myInfoObject.nvarchar50 = Convert.ToString(((TextBox)emptyRowCell.FindControl("txtAddnvarchar50")).Text);
                myInfoObject.nvarcharMax = Convert.ToString(((TextBox)emptyRowCell.FindControl("txtAddnvarcharMax")).Text);
                myInfoObject.VarcharMax = Convert.ToString(((TextBox)emptyRowCell.FindControl("txtAddVarcharMax")).Text);
                aNvarCharTestController myController = new aNvarCharTestController();
                myController.AddaNvarCharTest(myInfoObject);

                FillGrid();
            }
            // If grid is empty, the <EmptyDataTemplate> will be shown.
            if (e.CommandName.Equals("Update"))
            {
                aNvarCharTestInfo myInfoObject = new aNvarCharTestInfo();
                GridViewRow gvr;
                gvr = (GridViewRow)gvCSG.Rows[gvCSG.EditIndex];
                myInfoObject.aNvarChar_PK = Convert.ToInt32(((HiddenField)gvr.FindControl("txtAddaNvarChar_PK")).Value);
                myInfoObject.nvarchar10 = Convert.ToString(((TextBox)gvr.FindControl("txtEdtnvarchar10")).Text);
                myInfoObject.nvarchar25 = Convert.ToString(((TextBox)gvr.FindControl("txtEdtnvarchar25")).Text);
                myInfoObject.nvarchar50 = Convert.ToString(((TextBox)gvr.FindControl("txtEdtnvarchar50")).Text);
                myInfoObject.nvarcharMax = Convert.ToString(((TextBox)gvr.FindControl("txtEdtnvarcharMax")).Text);
                myInfoObject.VarcharMax = Convert.ToString(((TextBox)gvr.FindControl("txtEdtVarcharMax")).Text);
                aNvarCharTestController myController = new aNvarCharTestController();
                myController.UpdateaNvarCharTest(myInfoObject);

            }
        }
        protected void gvCSG_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvCSG.EditIndex = e.NewEditIndex;
            FillGrid();
        }
        protected void gvCSG_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            // If you need to add, edit, or transform the data as it is being,\r\n");
            //     updated to the row in the grid; add code here.\r\n");
            gvCSG.EditIndex = -1;
            FillGrid();
        }
        protected void gvCSG_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvCSG.EditIndex = -1;
            FillGrid();
        }
        protected void gvCSG_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 Id = Convert.ToInt32(gvCSG.DataKeys[e.RowIndex].Values[0].ToString());
            aNvarCharTestController myController = new aNvarCharTestController();
            myController.DeleteaNvarCharTest(Id);

            FillGrid();
        }

        #endregion

        #region "Optional Interfaces"

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// Registers the module actions required for interfacing with the portal framework 
        /// </summary> 
        /// <value></value> 
        /// <returns></returns> 
        /// <remarks></remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public ModuleActionCollection ModuleActions
        {
            get
            {
                ModuleActionCollection Actions = new ModuleActionCollection();
                Actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile),
                   ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit,
                    true, false);
                return Actions;
            }
        }

        #endregion

    }

}